Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for style selector parsing #619

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

marekdedic
Copy link
Contributor

@marekdedic marekdedic commented Dec 12, 2024

Copy link

changeset-bot bot commented Dec 12, 2024

🦋 Changeset detected

Latest commit: 243f4c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-eslint-parser Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Dec 12, 2024

Open in Stackblitz

npm i https://pkg.pr.new/svelte-eslint-parser@619

commit: 243f4c4

@marekdedic marekdedic force-pushed the selector-node-loc-fixing branch 7 times, most recently from 47e8c2b to 385e9ec Compare December 13, 2024 17:10
@coveralls
Copy link

Pull Request Test Coverage Report for Build 12330056473

Details

  • 84 of 93 (90.32%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.07%) to 94.75%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser/index.ts 23 25 92.0%
src/parser/style-context.ts 61 68 89.71%
Totals Coverage Status
Change from base Build 12251662727: -0.07%
Covered Lines: 10282
Relevant Lines: 10728

💛 - Coveralls

@marekdedic marekdedic force-pushed the selector-node-loc-fixing branch from ee0c676 to 53e9124 Compare December 14, 2024 14:19
Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added 1 more comment🙏 After solve this comment, I will merge this. @marekdedic

Comment on lines +147 to +160
export function styleSelectorNodeLoc(
node: SelectorNode,
): Partial<SourceLocation> {
return {
start:
node.source?.start !== undefined
? {
line: node.source.start.line,
column: node.source.start.column - 1,
}
: undefined,
end: node.source?.end,
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you do this in fixSelectorNodeLocation? I thought the loc information could always be handled in ESLint style because this program runs on ESLint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm following the same approach we agreed on in #340 (comment) - the TL;DR is that PostCSS AST locations are different than ESLint AST locations - one of them starts counting columns from 0 and other from 1, one of them has the end point at the last character while the other has it point at the first character after the end... So we agreed we would recalculate the positions to be relative to the whole file instead of being relative to the selector, but we would keep the PostCSS semantics in the PostCSS AST. Only when converting from PostCSS AST to an ESLint SourceLocation would we convert this to the ESLint way of doing things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course this is debatable (there is no universally "right" solution IMO), but I'd strongly suggest doing the selector parsing in the same way as the style node parsing. So if we were to change this one, we'd need to change the other one too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants